/*
    13. Write a C program to convert a string to an integer. 

    Test Data and Expected Output :

    Input a number : 1972                                                   
    The value Input is 1972.
*/

#include <stdio.h>
#include <string.h>

int str2int(char *str){
    int len = strlen(str);
    int i, j;
    int ret = 0, bit;
    for(i = 0; i < len; i++){
        j = len - i - 1;
        bit = 1;
        while(j--){
            bit = bit * 10;
        }
        ret += bit * (str[i] - '0');
    }
    return ret;
}

void main(void){
    printf("%d", str2int("123456"));
}